package Thread;

/**
 * @author: lqh
 * @description: thread-demo
 * @program: Demo
 * @create: 2018-04-13 15:58
 **/
public class demo1 {
    //如何让两个线程依次执行？
    /**
     * threadA.join() :  threadA线程优先
     * */
    static void  demo1(){
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                printStr("A");
            }
        });

        Thread threadB = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    threadA.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                printStr("B");
            }
        });
        threadB.start();
        threadA.start();
    }

   static void printStr(String threadName){
       int i=0;
       while (i++ < 3) {
           try {
               Thread.sleep(100);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           System.out.println(threadName + "-print:" + i);
       }
    }

    public static void main(String[] args) {
        demo1();
    }
}
